package com.jian.channel;

import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author Jiange
 * @create 2021-09-11-15:42
 */
public class FileChannelDemo2 {
    public static void main(String[] args) throws Exception {
        RandomAccessFile file = new RandomAccessFile("./1.txt", "rw");
        FileChannel channel = file.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);


        String str = "道东撒大婆萨吉大赛哦对撒泼大祭司哦啊的";
        buffer.clear();

        buffer.put(str.getBytes());
        buffer.flip();
        while (buffer.hasRemaining()){
            channel.write(buffer);
        }
        channel.close();
        file.close();

        //常用的方法  size  position  transforfrom  traansto
    }
}
